package com.qf.microuser.point.controller;

import com.qf.api.dto.PointDTO;
import com.qf.common.core.common.R;
import com.qf.common.core.entity.PointInfo;
import com.qf.common.core.entity.PointRule;
import com.qf.microuser.point.service.PointInfoService;
import com.qf.microuser.point.service.PointRuleService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * --- 缘分让我们相遇乱世以外 ---
 *
 * @author SJY
 * 2025/1/4
 */
@RestController
@RequestMapping("/user/point")
public class PointController {
    @Resource
    private PointInfoService pointInfoService;

    @Resource
    private PointRuleService pointRuleService;

    @PostMapping("/add/remote")
    public R remoteAddPoint(@RequestBody PointDTO pointDTO){
        PointInfo pointInfo = new PointInfo();
        BeanUtils.copyProperties(pointDTO,pointInfo);
        pointInfoService.addPointInfo(pointInfo);
        return R.ok();
    }

    @PostMapping("/add/rule")
    public R selPointRule(@RequestBody PointDTO pointDTO){
        PointRule pointRule = new PointRule();
        BeanUtils.copyProperties(pointDTO,pointRule);
        PointRule pointRule1 = pointRuleService.addPointRule(pointRule);
        Object point = pointRule1.getPoint();
        return R.ok(point);
    }


}
